package com.example.stumanager.admin;


import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.example.stumanager.HomepageLoginInterface;
import com.example.stumanager.R;
import com.example.stumanager.database.UserSql;
import com.example.stumanager.entity.UserEntity;

import java.util.ArrayList;

/**
 * 管理员首页
 */
public class AdminHomePage extends AppCompatActivity {
    ListView list;

    Button add, check, del, alter, mine, quit, addAnnouncement;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.admin_home_page);
        list = findViewById(R.id.list);

        add = findViewById(R.id.add);
        check = findViewById(R.id.check);
        del = findViewById(R.id.del);
        alter = findViewById(R.id.alter);
        mine = findViewById(R.id.mine);
        quit = findViewById(R.id.quit);
        addAnnouncement = findViewById(R.id.addAnnouncement);

        alter.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(AdminHomePage.this, AdminModifyStudentsPage.class);
            startActivity(intent);
        });
        del.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(AdminHomePage.this, AdminDelStudentsPage.class);
            startActivity(intent);
        });
        add.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(AdminHomePage.this, AdminAddStudentsPage.class);
            startActivity(intent);
        });
        check.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(AdminHomePage.this, AdminQueryStudentsPage.class);
            startActivity(intent);
        });
        mine.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(AdminHomePage.this, AdminPersonalCenterPage.class);
            startActivity(intent);
        });
        quit.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(AdminHomePage.this, HomepageLoginInterface.class);
            startActivity(intent);
        });
        addAnnouncement.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(AdminHomePage.this, AddAnnouncement.class);
            startActivity(intent);
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        set();
    }

    void set() {
        UserSql db = new UserSql(this);
        ArrayList<UserEntity> s = db.getAllWhere();
//        for (int i = 0; i < s.size(); i++) {
//            UserEntity userEntity = s.get(i);
//            if (userEntity.getPower() == 0) {
//                s.remove(userEntity);
//            }
//        }
        StudentInformationView adapter = new StudentInformationView(AdminHomePage.this, R.layout.student_information_view, s);
        list.setAdapter(adapter);
    }

}